package leetCode.solution;

public class Solution98 {

	public boolean isValidBST(TreeNode root) {
		return validBST(root,Long.MIN_VALUE, Long.MAX_VALUE);
	}
	
	public boolean validBST(TreeNode root, long min, long max) {
		if(root==null) return true;
		if(root.val<=min || root.val>=max) return false;
		return validBST(root.left, min, root.val) && validBST(root.right, root.val, max);
	}
	

	class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode() {
		}

		TreeNode(int val) {
			this.val = val;
		}

		TreeNode(int val, TreeNode left, TreeNode right) {
			this.val = val;
			this.left = left;
			this.right = right;
		}
	}

}
